home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / PROGRAMS / CH4 / 4-2-3.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-11-02  |  3.0 KB  |  99 lines

  1. VERSION 5.00
  2. Begin VB.Form frmAdd 
  3.    Caption         =   "Add Two Numbers"
  4.    ClientHeight    =   1695
  5.    ClientLeft      =   3300
  6.    ClientTop       =   3060
  7.    ClientWidth     =   2775
  8.    BeginProperty Font 
  9.       Name            =   "MS Sans Serif"
  10.       Size            =   8.25
  11.       Charset         =   0
  12.       Weight          =   700
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    LinkTopic       =   "Form1"
  18.    PaletteMode     =   1  'UseZOrder
  19.    ScaleHeight     =   1695
  20.    ScaleWidth      =   2775
  21.    Begin VB.PictureBox picResult 
  22.       AutoRedraw      =   -1  'True
  23.       Height          =   255
  24.       Left            =   120
  25.       ScaleHeight     =   195
  26.       ScaleWidth      =   2475
  27.       TabIndex        =   5
  28.       Top             =   1320
  29.       Width           =   2535
  30.    End
  31.    Begin VB.CommandButton cmdCompute 
  32.       Caption         =   "Compute Sum"
  33.       Height          =   375
  34.       Left            =   600
  35.       TabIndex        =   4
  36.       Top             =   840
  37.       Width           =   1575
  38.    End
  39.    Begin VB.TextBox txtSecondNum 
  40.       Height          =   285
  41.       Left            =   1680
  42.       TabIndex        =   1
  43.       Top             =   480
  44.       Width           =   975
  45.    End
  46.    Begin VB.TextBox txtFirstNum 
  47.       Height          =   285
  48.       Left            =   1680
  49.       TabIndex        =   0
  50.       Top             =   120
  51.       Width           =   975
  52.    End
  53.    Begin VB.Label lblSecondNum 
  54.       AutoSize        =   -1  'True
  55.       Caption         =   "Second Number"
  56.       Height          =   195
  57.       Left            =   240
  58.       TabIndex        =   3
  59.       Top             =   480
  60.       Width           =   1365
  61.    End
  62.    Begin VB.Label lblFirstNum 
  63.       AutoSize        =   -1  'True
  64.       Caption         =   "First Number"
  65.       Height          =   195
  66.       Left            =   480
  67.       TabIndex        =   2
  68.       Top             =   120
  69.       Width           =   1095
  70.       WordWrap        =   -1  'True
  71.    End
  72. Attribute VB_Name = "frmAdd"
  73. Attribute VB_GlobalNameSpace = False
  74. Attribute VB_Creatable = False
  75. Attribute VB_PredeclaredId = True
  76. Attribute VB_Exposed = False
  77. Private Sub cmdCompute_Click()
  78.   Dim x As Single, y As Single, s As Single
  79.   'Display the sum of two numbers
  80.   Call GetNumbers(x, y)
  81.   Call CalculateSum(x, y, s)
  82.   Call DisplayResult(x, y, s)
  83. End Sub
  84. Private Sub CalculateSum(num1 As Single, num2 As Single, sum As Single)
  85.   'Add the values of num1 and num2
  86.   'and assign the value to sum
  87.    sum = num1 + num2
  88. End Sub
  89. Private Sub DisplayResult(num1 As Single, num2 As Single, sum As Single)
  90.   'Display a sentence giving the two numbers and their sum
  91.   picResult.Cls
  92.   picResult.Print "The sum of"; num1; "and"; num2; "is"; sum
  93. End Sub
  94. Private Sub GetNumbers(num1 As Single, num2 As Single)
  95.   'Record the two numbers in the text boxes
  96.    num1 = Val(txtFirstNum.Text)
  97.    num2 = Val(txtSecondNum.Text)
  98. End Sub
  99.